package com.qinggeng.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.project.system.domain.SysAdver;
import com.qinggeng.project.system.service.ISysAdverService;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.web.page.TableDataInfo;

/**
 * 广告管理Controller
 * 
 * @author qinggeng
 * @date 2020-02-12
 */
@RestController
@RequestMapping("/system/adver")
public class AdverController extends BaseController
{
    @Autowired
    private ISysAdverService adverService;

    /**
     * 查询广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:adver:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAdver adver)
    {
        startPage();
        List<SysAdver> list = adverService.selectSysAdverList(adver);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:adver:export')")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysAdver adver)
    {
        List<SysAdver> list = adverService.selectSysAdverList(adver);
        ExcelUtil<SysAdver> util = new ExcelUtil<SysAdver>(SysAdver.class);
        return util.exportExcel(list, "adver");
    }

    /**
     * 获取广告管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:adver:query')")
    @GetMapping(value = "/{adverId}")
    public AjaxResult getInfo(@PathVariable("adverId") Long adverId)
    {
        return AjaxResult.success(adverService.selectSysAdverById(adverId));
    }

    /**
     * 新增广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:adver:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAdver adver)
    {
        return toAjax(adverService.insertSysAdver(adver));
    }

    /**
     * 修改广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:adver:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAdver adver)
    {
        return toAjax(adverService.updateSysAdver(adver));
    }

    /**
     * 删除广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:adver:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adverIds}")
    public AjaxResult remove(@PathVariable Long[] adverIds)
    {
        return toAjax(adverService.deleteSysAdverByIds(adverIds));
    }
}
